//Source file: D:\\test\\com\\ce\\pms\\charge\\model\\DebitTransDomain.java

package com.ce.pms.charge.model;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.ce.pms.common.model.SysInfo;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.util.BlankUtil;

/**
 * 应收交易
 *
 * @author Adama Yue
 * @CreateDate:2008-7-14
 */
@Entity
@DiscriminatorValue("DE")
public class DebitTransDomain extends AbstractTrans {

	/**
	 * 借
	 */
	@Column(name = "DEBIT", precision = 18, scale = 2)
	private BigDecimal debit = new BigDecimal("0.00");

	/**
	 * 交易状态:001未缴;002已缴;003全额减免;004挂起;005出盘锁定
	 */
	@Column(name = "STATUZ", nullable = false, length = 3)
	private String statuz;

	/**
	 * 收费标准版本
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "STA_HIS_ID")
	private AbstractStaVersion staVersion;

	/**
	 * 来源房间
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "HOUSE_ID")
	private HouseDomain house;

	/***
	 * 消费日期
	 */
	@Temporal(TemporalType.DATE)
	@Column(name="INPUT_DATE")
	private Date inputDate;

	/***
	 * 主交易ID
	 */
	@Column(name="M_TRANS_ID")
	private Long mTransId;

	/**
	 * 走表数据
	 */
	@OneToMany
	//@org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	@JoinTable(name = "FEE_CHARGE_DATAS_R_TRANSACTION",
			joinColumns = { @JoinColumn(name = "TRANSACTION_ID") },
			inverseJoinColumns = { @JoinColumn(name = "CHARGE_DATA_ID") })
	private Set<ChargeDatasDomain> chargeDatas = new HashSet<ChargeDatasDomain>();

	/**
	 * 滞纳金明细.
	 */
	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "debitTrans")
	private Set<LatefeeDetail> lateFees = new HashSet<LatefeeDetail>();

	/**
	 * @roseuid 48757D1301D4
	 */
	public DebitTransDomain() {

	}

	/**
	 * mini constructor
	 *
	 * @param period
	 *            收费周期
	 * @param businessCode
	 *            交易码
	 * @param bindingAccount
	 *            子帐户
	 * @param clazz
	 *            类型 收费类交易: 001本金交易;002减免交易;003调整交易;004滞纳金交易
	 * @param statuz
	 *            交易状态:001未缴;002已缴;003全额减免;004挂起;005出盘锁定
	 * @param sysInfo
	 *            系统信息
	 */
	public DebitTransDomain(PeriodDomain period,
			BusinessCodeDomain businessCode, AbstractStaVersion staVersion,
			AbstractSubAccount bindingAccount, HouseDomain house, String clazz,
			String statuz, SysInfo sysInfo) {
		super(period, businessCode, bindingAccount, clazz, sysInfo);
		this.staVersion = staVersion;
		this.statuz = statuz;
		this.house = house;
	}

	public Set<ChargeDatasDomain> getChargeDatas() {
		return chargeDatas;
	}

	public void setChargeDatas(Set<ChargeDatasDomain> chargeDatas) {
		this.chargeDatas = chargeDatas;
	}

	public BigDecimal getDebit() {
		return debit;
	}

	public void setDebit(BigDecimal debit) {
		this.debit = debit;
	}

	public Set<LatefeeDetail> getLateFees() {
		return lateFees;
	}

	public void setLateFees(Set<LatefeeDetail> lateFees) {
		this.lateFees = lateFees;
	}

	public String getStatuz() {
		return statuz;
	}

	public void setStatuz(String statuz) {
		this.statuz = statuz;
	}

	public HouseDomain getHouse() {
		return house;
	}

	public void setHouse(HouseDomain house) {
		this.house = house;
	}

	public AbstractStaVersion getStaVersion() {
		return staVersion;
	}

	public void setStaVersion(AbstractStaVersion staVersion) {
		this.staVersion = staVersion;
	}

	/*
	 * (non-Javadoc)
	 * @see com.ce.pms.charge.model.AbstractTrans#checkRequiredField()
	 */
	@Override
	public void checkRequiredField() {
		super.checkRequiredField();
		if (this.debit==null
				|| BlankUtil.isBlank(this.statuz)) {
			throw new BusinessException("common:mustFill_null_exception",
					BusinessException.WARNING);
		}
		if (0 == BigDecimal.ZERO.compareTo(this.debit)) {
			throw new BusinessException("charge:charge_transaction_not_zero_exception",BusinessException.WARNING);
		}
	}

	public Date getInputDate() {
		return inputDate;
	}

	public void setInputDate(Date inputDate) {
		this.inputDate = inputDate;
	}



	public Long getMTransId() {
		return mTransId;
	}

	public void setMTransId(Long transId) {
		mTransId = transId;
	}

	/**
	 * 功能描述: 改变应收交易状态 <br>
	 * @param statuz
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-6  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Boolean changeTransStatus(String statuz){
		this.statuz=statuz;
		return true;
	}
}
